package Service;

import Monitor.ClientThread;
import Utils.PacketUtils;
import Utils.ThreadManage;
import org.json.JSONObject;

import java.io.IOException;

/**
 * The type Send msg.
 *
 * @author dzr
 * @version 1.0
 */
public class SendMsg {
    /**
     * The constant SEND_MSG.
     */
    public static final int SEND_MSG = 3;

    /**
     * Send message.
     *
     * @param s_uid   the sender's uid
     * @param r_uid   the receiver's uid
     * @param time    the time
     * @param content the content
     * @throws IOException the io exception
     */
    public static void sendMsg(int s_uid, int r_uid, String time, String content) throws IOException {
        JSONObject ret2Server = new JSONObject();
        ClientThread thread = ThreadManage.getInstance().getClientThreads().get(s_uid);

        String s_name = thread.getUsername();
        ret2Server.put("cmd", SEND_MSG);
        ret2Server.put("s_uid", s_uid);
        ret2Server.put("s_name", s_name);
        ret2Server.put("r_uid", r_uid);
        ret2Server.put("content", content);
        ret2Server.put("time", time);

        PacketUtils.sendPacket(ret2Server);
    }
}
